package com.paas.form.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.text.ParseException;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.paas.common.util.BeanUtil;
import com.paas.common.model.RestResponse;
import com.paas.common.web.annotion.OperLog;
import com.paas.common.web.controller.BaseController;
import com.paas.common.web.oper.OprLogConstant;
import com.paas.common.token.TokenModel;


import com.paas.form.entity.AtestFormCodeEntity;
import com.paas.form.service.IAtestFormCodeService;

@RestController
@RequestMapping(value = "/dev/atestFormCode")
@Api(description = "代码下载测试", tags = "")
public class AtestFormCodeController extends BaseController{

    @Autowired
    public IAtestFormCodeService atestFormCodeService;

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ApiOperation(value = "保存信息", notes = "保存信息")
    @OperLog(operType = OprLogConstant.ADD, operModul = "", operDescribe = "-保存")
    public void save(@RequestBody AtestFormCodeEntity atestFormCodeEntity)throws ParseException{
        if(BeanUtil.isNotEmpty(atestFormCodeEntity)){
            injectUpdateDataAuth(atestFormCodeEntity);
        }
        atestFormCodeService.save(atestFormCodeEntity);
    }

    @RequestMapping(value = "/saveBatch", method = RequestMethod.POST)
    @ApiOperation(value = "批量保存信息", notes = "批量保存信息")
    @OperLog(operType = OprLogConstant.UPDATE, operModul = "", operDescribe = "-批量保存修改")
    public void saveBatch(@RequestBody List<AtestFormCodeEntity> list) throws ParseException{
        if(list!=null && list.size()>0){
            injectUpdateDataAuth(list);
        }
        atestFormCodeService.saveBatch(list);
    }

    @RequestMapping(value = "/deleteById", method = RequestMethod.GET)
    @ApiOperation(value = "根据Id删除数据", notes = "根据Id删除数据")
    @OperLog(operType = OprLogConstant.DELETE, operModul = "", operDescribe = "-删除")
    public void deleteById(String id){
        if(null!=id && !"".equals(id)){
            AtestFormCodeEntity atestFormCodeEntity=new AtestFormCodeEntity();
            injectUpdateDataAuth(atestFormCodeEntity);
            atestFormCodeEntity.setId(id);
            atestFormCodeService.deleteByEntity(atestFormCodeEntity);
        }
    }

    @RequestMapping(value = "/deleteBatchByIds", method = RequestMethod.POST)
    @ApiOperation(value = "根据Id批量删除数据", notes = "根据Id批量删除数据")
    @OperLog(operType = OprLogConstant.DELETE, operModul = "", operDescribe = "-批量删除")
    public void deleteBatchByIds(@RequestBody List <String> ids){
        if (null != ids && ids.size() > 0) {
            AtestFormCodeEntity atestFormCodeEntity=new AtestFormCodeEntity();
            injectUpdateDataAuth(atestFormCodeEntity);
            //atestFormCodeService.deleteBatchIds(ids);
            atestFormCodeService.deleteBatchIdsWithPermission(ids,atestFormCodeEntity);
        }
    }

    @RequestMapping(value = "/queryById", method = RequestMethod.GET)
    @ApiOperation(value = "根据Id查询对象", notes = "根据Id查询对象")
    public AtestFormCodeEntity queryById(String id){
        AtestFormCodeEntity bean=atestFormCodeService.getById(id);
        return bean;
    }

    @RequestMapping(value = "/queryBatchByIds", method = RequestMethod.POST)
    @ApiOperation(value = "根据Id查询对象列表", notes = "根据Id查询对象列表")
    public List<AtestFormCodeEntity> queryBatchByIds(@RequestBody List<String> ids){
        List<AtestFormCodeEntity> list=atestFormCodeService.getBatchByIds(ids);
        return list;
    }

    @RequestMapping(value = "/queryPage", method = RequestMethod.GET)
    @ApiOperation(value = "模板分页查询", notes = "模板分页查询")
    public IPage<AtestFormCodeEntity> queryPage(AtestFormCodeEntity atestFormCodeEntity,Integer currentPage,Integer pageSize){
        if(currentPage==null){
            currentPage=1;
        }
        if(pageSize==null){
            pageSize=10;
        }
        injectCheckDataAuth(atestFormCodeEntity);
        IPage<AtestFormCodeEntity> pageBean=atestFormCodeService.getPage(atestFormCodeEntity,currentPage,pageSize);
        return pageBean;
    }

    @RequestMapping(value = "/queryList", method = RequestMethod.GET)
    @ApiOperation(value = "模板查询", notes = "模板查询")
    public List<AtestFormCodeEntity> queryList(AtestFormCodeEntity atestFormCodeEntity){
        injectCheckDataAuth(atestFormCodeEntity);
        List<AtestFormCodeEntity> list=atestFormCodeService.getList(atestFormCodeEntity);
        return list;
    }
}